package demo.datetime;

import org.joda.time.DateTime;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * description: <br>
 * createTime: 2020/5/2911:55 <br>
 *
 * @author zzh
 */
public class DateTimeDemo {

    public static void main(String[] args) {
        // LocalDate LocalTime LocalDateTime
        // 获取当前时间
        LocalDate localDate = LocalDate.now();
        LocalTime localTime = LocalTime.now();
        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDate);
        System.out.println(localTime);
        System.out.println(localDateTime);

        // LocalDateTime  使用频率较高
        // of() 设置指定的年月日时分秒  体现不偏移性
        LocalDateTime dateTime = LocalDateTime.of(2019, 04, 10, 23, 03);
        System.out.println(dateTime);

        // getXxx()
        System.out.println(dateTime.getDayOfMonth());
        System.out.println(dateTime.getDayOfWeek());
        System.out.println(dateTime.getMonth());
        System.out.println(dateTime.getMinute());
        System.out.println(dateTime.getMonthValue());

        // withXxx   体现不可变性
        LocalDate localDate1 = localDate.withDayOfMonth(12);
        System.out.println(localDate);
        System.out.println(localDate1);
        // 设置分钟
        LocalDateTime localDateTime1 = localDateTime.withMinute(20);
        System.out.println(localDateTime);
        System.out.println(localDateTime1);

        // plusXxx()   当前的时间做加法
        LocalDate localDate2 = localDate.plusMonths(1);
        System.out.println(localDate);
        System.out.println(localDate2);
    }
}
